package com.coreJava.shejimoshi.cglibdongtaidaili;

import com.alibaba.fastjson.JSON;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 作者: LCG
 * 日期: 2020/2/13 20:11
 * 描述:
 */
public class TestGetProxyObject00<T> implements MethodInterceptor {

    private Enhancer enhancer=new Enhancer();

    public T getProxyObject(Class<T> tClass){

        enhancer.setSuperclass(tClass);

        enhancer.setCallback(this);

        return (T)enhancer.create();

    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println(JSON.toJSONString(objects));

        return "ok";
    }
}